Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sockets - Grace #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Sockets - Grace #22

wants to merge 1 commit into from

Conversation

gracemshea
Copy link

Heaps Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
How is a Heap different from a Binary Search Tree?
Could you build a heap with linked nodes?
Why is adding a node to a heap an O(log n) operation?
Were the heap_up & heap_down methods useful? Why?

Copy link

@CheezItMan CheezItMan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, there's a bug with heap_down, see my comment on it and let me know any questions you have. Otherwise not bad. Also consider recursion and time complexity.

else
min = [left, right].min_by {|x| @store[x].key}
end
swap(index, min)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't quite working because you're not checking to see if the element at index is greater than the element at min.

 if @store[index] > @store[min]
    swap(index, min)
    heap_down(min)
end

# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: 0(n log n)
# Space Complexity: 0(1)
def heap_sort(list)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not working due to a bug in heap_down

# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: 0(log n)
# Space Complexity: 0(1)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since heap_down is recursive you have to consider the impact of the recursion on space complexity.

# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: 0(log n)
# Space Complexity: 0(1)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto for heap_up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants